//
//  VisitorTableViewController.swift
//  Weibo
//
//  Created by 孙明海 on 16/1/23.
//  Copyright © 2016年 孙明海. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    //设置登陆标记
    var userLogin = UserAccountViewModel.sharedUserAccount.userLogin
    
    var visitorView: VisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func loadView() {
        userLogin ? super.loadView() : setVisitorView()
    }
    /// 设置访客视图
    private func setVisitorView() {
        visitorView = VisitorView()
        view = visitorView
        //监听点击事件
        visitorView?.registerButton.addTarget(self, action: "visiterViewDidClickRegister", forControlEvents: .TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visiterViewDidClickLogin", forControlEvents: .TouchUpInside)
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visiterViewDidClickRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "visiterViewDidClickLogin")
    }
}
//MARK: - 监听方法
extension VisitorTableViewController {
    @objc private func visiterViewDidClickRegister() {
        print("注册")
    }
    @objc private func visiterViewDidClickLogin() {
        print("登陆")
        
        let oauthVc = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauthVc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}
